package o;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Build.VERSION;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import com.tencent.mm.opensdk.constants.ConstantsAPI.AppSupportContentFlag;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class dok {
    private static String ˋ = "";
    private static long ˎ;
    private static Map<String, Object> ॱ = new ConcurrentHashMap();

    public static String ˊ() {
        return ˋ;
    }

    public static void ॱ(Context context) {
        ˋ(context);
        ॱˊ();
    }

    public static long ˋ(Context context) {
        Long l = (Long) ॱ.get("TotalMem");
        if (l != null) {
            return l.longValue();
        }
        long ॱॱ;
        if (doe.ˏ()) {
            ॱॱ = ॱॱ(context);
        } else {
            ॱॱ = ʻ(context);
        }
        if (ॱॱ > 0) {
            ॱ.put("TotalMem", Long.valueOf(ॱॱ));
            ˎ = ॱॱ;
        }
        Logger.ˎ("DeviceUtil", "getTotalMem: " + ॱॱ);
        return ॱॱ;
    }

    @SuppressLint({"NewApi"})
    private static long ॱॱ(Context context) {
        try {
            ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
            MemoryInfo memoryInfo = new MemoryInfo();
            activityManager.getMemoryInfo(memoryInfo);
            return memoryInfo.totalMem;
        } catch (Exception e) {
            Logger.e("DeviceUtil", e.getMessage());
            return 0;
        }
    }

    private static long ʻ(Context context) {
        IOException e;
        NumberFormatException e2;
        Throwable th;
        UnsupportedEncodingException e3;
        long j = 0;
        BufferedReader bufferedReader = null;
        BufferedReader bufferedReader2;
        try {
            bufferedReader2 = new BufferedReader(new InputStreamReader(new FileInputStream("/proc/meminfo"), "UTF-8"));
            try {
                String readLine = bufferedReader2.readLine();
                if (readLine != null) {
                    j = Long.parseLong(readLine.split("\\s+")[1]);
                }
                if (bufferedReader2 != null) {
                    try {
                        bufferedReader2.close();
                    } catch (IOException e4) {
                        Logger.e("DeviceUtil", e4.getMessage());
                    }
                }
            } catch (NumberFormatException e5) {
                e2 = e5;
                try {
                    Logger.e("DeviceUtil", e2.getMessage());
                    if (bufferedReader2 != null) {
                        try {
                            bufferedReader2.close();
                        } catch (IOException e42) {
                            Logger.e("DeviceUtil", e42.getMessage());
                        }
                    }
                    return j * AppSupportContentFlag.MMAPP_SUPPORT_XLS;
                } catch (Throwable th2) {
                    th = th2;
                    bufferedReader = bufferedReader2;
                    if (bufferedReader != null) {
                        try {
                            bufferedReader.close();
                        } catch (IOException e6) {
                            Logger.e("DeviceUtil", e6.getMessage());
                        }
                    }
                    throw th;
                }
            } catch (UnsupportedEncodingException e7) {
                e3 = e7;
                bufferedReader = bufferedReader2;
                try {
                    Logger.e("DeviceUtil", e3.getMessage());
                    if (bufferedReader != null) {
                        try {
                            bufferedReader.close();
                        } catch (IOException e422) {
                            Logger.e("DeviceUtil", e422.getMessage());
                        }
                    }
                    return j * AppSupportContentFlag.MMAPP_SUPPORT_XLS;
                } catch (Throwable th3) {
                    th = th3;
                    if (bufferedReader != null) {
                        bufferedReader.close();
                    }
                    throw th;
                }
            } catch (FileNotFoundException e8) {
                bufferedReader = bufferedReader2;
                Logger.e("DeviceUtil", "getTotalMemFromFile FileNotFoundException");
                if (bufferedReader != null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException e4222) {
                        Logger.e("DeviceUtil", e4222.getMessage());
                    }
                }
                return j * AppSupportContentFlag.MMAPP_SUPPORT_XLS;
            } catch (IOException e9) {
                e4222 = e9;
                bufferedReader = bufferedReader2;
                Logger.e("DeviceUtil", e4222.getMessage());
                if (bufferedReader != null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException e42222) {
                        Logger.e("DeviceUtil", e42222.getMessage());
                    }
                }
                return j * AppSupportContentFlag.MMAPP_SUPPORT_XLS;
            }
        } catch (NumberFormatException e10) {
            e2 = e10;
            bufferedReader2 = null;
            Logger.e("DeviceUtil", e2.getMessage());
            if (bufferedReader2 != null) {
                bufferedReader2.close();
            }
            return j * AppSupportContentFlag.MMAPP_SUPPORT_XLS;
        } catch (UnsupportedEncodingException e11) {
            e3 = e11;
            Logger.e("DeviceUtil", e3.getMessage());
            if (bufferedReader != null) {
                bufferedReader.close();
            }
            return j * AppSupportContentFlag.MMAPP_SUPPORT_XLS;
        } catch (FileNotFoundException e12) {
            Logger.e("DeviceUtil", "getTotalMemFromFile FileNotFoundException");
            if (bufferedReader != null) {
                bufferedReader.close();
            }
            return j * AppSupportContentFlag.MMAPP_SUPPORT_XLS;
        } catch (IOException e13) {
            e42222 = e13;
            Logger.e("DeviceUtil", e42222.getMessage());
            if (bufferedReader != null) {
                bufferedReader.close();
            }
            return j * AppSupportContentFlag.MMAPP_SUPPORT_XLS;
        }
        return j * AppSupportContentFlag.MMAPP_SUPPORT_XLS;
    }

    public static DisplayMetrics ˏ(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService("window");
        if (windowManager != null) {
            Display defaultDisplay = windowManager.getDefaultDisplay();
            if (defaultDisplay != null) {
                DisplayMetrics displayMetrics = new DisplayMetrics();
                defaultDisplay.getRealMetrics(displayMetrics);
                return displayMetrics;
            }
        }
        return null;
    }

    public static String ˋ() {
        return Build.MODEL;
    }

    public static String ˏ() {
        return VERSION.RELEASE;
    }

    public static String ॱ() {
        return String.valueOf(VERSION.SDK_INT);
    }

    public static String ˎ() {
        try {
            Object obj = Class.forName("com.huawei.system.BuildEx").getField("DISPLAY").get(null);
            return obj == null ? Build.DISPLAY : obj.toString();
        } catch (IllegalAccessException e) {
            return Build.DISPLAY;
        } catch (NoSuchFieldException e2) {
            return Build.DISPLAY;
        } catch (ClassNotFoundException e3) {
            return Build.DISPLAY;
        }
    }

    private static void ॱˊ() {
        Object obj;
        Object country;
        Object obj2 = "en";
        String str = "";
        String str2 = "US";
        Locale locale = Locale.getDefault();
        if (locale != null) {
            obj2 = locale.getLanguage();
            if (VERSION.SDK_INT >= 21) {
                str = locale.getScript();
            }
            obj = str;
            country = locale.getCountry();
        } else {
            String str3 = str2;
            str2 = str;
            str = str3;
        }
        if (TextUtils.isEmpty(obj2)) {
            obj2 = "en";
        }
        if (TextUtils.isEmpty(obj)) {
            obj = "";
        }
        if (TextUtils.isEmpty(country)) {
            country = "US";
        }
        ॱ.put("Lang", obj2);
        ॱ.put("Script", obj);
        ॱ.put("Country", country);
    }

    public static String ॱॱ() {
        String str = (String) ॱ.get("Country");
        if (!TextUtils.isEmpty(str)) {
            return str;
        }
        ॱˊ();
        return (String) ॱ.get("Country");
    }

    public static String ʼ() {
        String str = (String) ॱ.get("Script");
        if (str != null) {
            return str;
        }
        ॱˊ();
        return (String) ॱ.get("Script");
    }

    public static void ʽ() {
        ॱ.put("Lang", "");
        ॱ.put("Script", "");
        ॱ.put("Country", "");
    }

    public static String ᐝ() {
        String str = (String) ॱ.get("Lang");
        if (!TextUtils.isEmpty(str)) {
            return str;
        }
        ॱˊ();
        return (String) ॱ.get("Lang");
    }

    public static String ʻ() {
        String str = "";
        DisplayMetrics ˏ = ˏ(ContentManager.getInstant().getContext());
        if (ˏ != null) {
            return String.valueOf(ˏ.densityDpi);
        }
        return str;
    }

    public static String ˊॱ() {
        String str = "";
        DisplayMetrics ˏ = ˏ(ContentManager.getInstant().getContext());
        if (ˏ == null) {
            return str;
        }
        str = String.valueOf(ˏ.widthPixels);
        return str + "_" + String.valueOf(ˏ.heightPixels);
    }

    @Deprecated
    public static boolean ͺ() {
        return doo.ˊ(ContentManager.getInstant().getContext());
    }

    public static int ˊ(Context context) {
        return aoj.ˏ().ˊ(context);
    }

    public static boolean ˋॱ() {
        Context ˋ = ContentManager.getInstant().getContext();
        try {
            if ((ˋ.getPackageManager().getPackageInfo("com.google.android.gms", 0).applicationInfo.flags & 1) == 1) {
                int ˊ = ˊ(ˋ);
                if (ˊ == 0 || ˊ == 2) {
                    return true;
                }
            }
            return false;
        } catch (NameNotFoundException e) {
            Logger.ˋ("DeviceUtil", "Google Play services is missing.");
            return false;
        }
    }

    public static boolean ˎ(Context context) {
        if (context.getResources().getConfiguration().orientation == 2) {
            return true;
        }
        return false;
    }

    public static int ˏॱ() {
        try {
            Class cls = Class.forName("android.os.UserHandle");
            return ((Integer) cls.getMethod("myUserId", new Class[0]).invoke(cls, new Object[0])).intValue();
        } catch (IllegalArgumentException e) {
            Logger.e("DeviceUtil", "get current uid IllegalArgumentException! " + e.toString());
            return 0;
        } catch (ClassNotFoundException e2) {
            Logger.e("DeviceUtil", "get current uid ClassNotFoundException! " + e2.toString());
            return 0;
        } catch (NoSuchMethodException e3) {
            Logger.e("DeviceUtil", "get current uid NoSuchMethodException! " + e3.toString());
            return 0;
        } catch (InvocationTargetException e4) {
            Logger.e("DeviceUtil", "get current uid InvocationTargetException! " + e4.toString());
            return 0;
        } catch (IllegalAccessException e5) {
            Logger.e("DeviceUtil", "get current uid IllegalAccessException! " + e5.toString());
            return 0;
        }
    }

    public static boolean ᐝ(Context context) {
        if (ˎ == 0) {
            ˎ = ॱॱ(context);
        }
        return ˎ <= 3221225472L;
    }
}
